package com.haiyou.dc.thread;

public class TestJoin2 {

    public static void main(String[] args) {
        new Father().start();
    }

    static class Father extends Thread {
        @Override
        public void run() {

            System.out.println("想抽烟，发现没有烟...");
            System.out.println("把零钱给孩子.....");
            Sun sun = new Sun();
            sun.start();
            try {
                //保证线程顺序，让孩子执行完再执行后面线程
                sun.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("老爸拿到烟抽起来...");

        }
    }

    static class Sun extends Thread {
        @Override
        public void run() {
            System.out.println("孩子拿到钱...");
            System.out.println("看到游戏厅...");
            for (int i = 0; i < 10; i++) {
                System.out.println("玩游戏...." + i);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("买了烟.....");
            System.out.println("孩子拿了烟回来...");
        }
    }
}

